package com.lian.community.dao.user;

import com.lian.community.dao.post.PostPO;
import com.lian.community.dao.user.po.UserPO;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

@Mapper
public interface PostDAO {

    String TABLE_NAME = "e_post";
    String USER_POST_TABLE_NAME = "r_user_post";
    String INSERT_FIELDS = "title, content";
    String SELECT_FIELDS = "id, title, create_time createTime, content";

    @Insert({"insert into ", TABLE_NAME, "(",INSERT_FIELDS,")","values(#{title}, #{content})"})
    void insert(PostPO postPO);

    @Select({"select", SELECT_FIELDS, " from ", TABLE_NAME, "where id = #{id}"})
    PostPO selectById(@Param("id")int id);

    @Select({"select last_insert_id()"})
    Integer lastInsertId();

    @Insert({"insert into ", USER_POST_TABLE_NAME, "(user_id, post_id) values(#{userId}, #{postId})"})
    void insertUserPost(@Param("userId")int userId, @Param("postId")int postId);




}
